<?php
class Zend_View_Helper_Link extends Zend_View_Helper_Abstract
{
    public $view;

    public function link($url, $param = array(), $text = '', $opt = array())
    {
        $replace = isset($opt['replace']) ? $opt['replace'] : '-';
        $target = isset($opt['target']) ? $opt['target'] : 'main';
        $id = isset($opt['id']) ? sprintf('id = "%s"', $opt['id']) : '';
        
        if(!isset(Zend_Auth::getInstance()->getIdentity()->resources[str_replace('/','.',trim($url,'/'))]))
            return isset($opt['text']) ? sprintf('<a style="text-decoration: none">%s</a>', $text) : '';
            //return $text ? $text : $replace;
        if($text) {
            foreach($param as $par => $val) {
                if (!$val) $url .= sprintf('/%s', $par);
                else $url .= sprintf('/%s/%s', $par, $val);
            }
            return sprintf("<a %s target='%s' href='%s'>%s</a>", $id, $target, $url, $text);
        }
        return $replace;
    }

    public function setView(Zend_View_Interface $view)
    {
        $this->view = $view;
    }
}
?>